package com.cloudptt.wp.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.UpdateUiListener;
import com.cloudptt.api.product.func.message.AppLogListener;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;
import com.cloudptt.wp.SysApplication;
import com.cloudptt.wp.ui.call.FloorDlg;

public abstract class BaseActivity extends Activity implements AppLogListener, UpdateUiListener,EventListener {

	private BaseBroadcast bc = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		bc = new BaseBroadcast(BaseActivity.this,BaseActivity.this);
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.debug(BaseActivity.class, "onKeyDown keyCode = "+ keyCode);
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			ScreenManager.getScreenManager().popActivity();
			return true;
		} else
			return super.onKeyDown(keyCode, event);
	}
	@Override
	protected void onResume() {
		super.onResume();
		SysApplication app = ((SysApplication) getApplicationContext());
		app.setUpdateUiListener(this);
		Product product = app.getProduct();
		if(product != null) {
			product.setAppLogListener(this);
		}
	}
	@Override
	public void finish() {
		super.finish( );
		if(bc != null)
		{
			bc.clearResource();
		}
		overridePendingTransition( R.anim.in_from_left,
				R.anim.out_to_right );
	}
	@Override
	public void receiveNotify()
	{
		Log.debug(BaseActivity.class,"receiveNotify");
		SysApplication app = ((SysApplication) getApplicationContext());
		Product product = app.getProduct();
		product.beginUpload(BaseActivity.this,null);
	}
	public void UpdateUi(int type,String name)
	{

	}
	public void showHalfCallDlg(String addrName)
	{
//		Log.debug(BaseActivity.class,"showHalfCallDlg FloorDlg.isShow = " + FloorDlg.isShow);
//		if(!FloorDlg.isShow) {
//			FloorDlg.showDialog(this, addrName);
		Intent intent = new Intent(BaseActivity.this, FloorDlg.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra(FloorDlg.KEY,addrName);

		startActivityForResult(intent, 100);
		//	}
	}

	public void onHangup(int type){
		Log.debug(BaseActivity.class, "onHangup type "+ type);
		ScreenManager.getScreenManager().popActivity();
	}
}
